//    Copyright (C) Kherty.  All rights reserved.
using OpenLS.Core.Serialization;

namespace OpenLS.Spreadsheet.Data
{
    public class WebQueryConnection: DataConnection
    {  

        internal override void  ReadProperties(ReadContext context)
{
 	        using (ReadContext c = context.Read("webPr"))
            {
                Xml = c.GetOptionalBoolean("xml", false);
                SourceData = c.GetOptionalBoolean("sourceData", false);
                ParsePre = c.GetOptionalBoolean("parsePre", false);
                Consecutive = c.GetOptionalBoolean("consecutive", false);
                FirstRow = c.GetOptionalBoolean("firstRow", false);
                Xl97 = c.GetOptionalBoolean("xl97", false);
                Xl2000 = c.GetOptionalBoolean("xl2000", false);
                DatesAsText = c.GetOptionalBoolean("textDates", false);
                Url = c.GetOptionalString("url");
                Post = c.GetOptionalString("post");
                HtmlTables = c.GetOptionalBoolean("htmlTables", false);
                HtmlFormat = c.GetOptionalEnum<HtmlFormat>("htmlFormat", HtmlFormat.None);
                EditPage = c.GetOptionalString("editPage");

                Tables = c.ReadOptionalElement<Tables>("tables");
            }
        }

        internal override void  WriteProperties(WriteContext context)
{
 	        using (WriteContext c = context.Write("webPr"))
            {
                c.SetOptionalBoolean("xml", Xml, false);
                c.SetOptionalBoolean("sourceData", SourceData, false);
                c.SetOptionalBoolean("parsePre", ParsePre, false);
                c.SetOptionalBoolean("consecutive", Consecutive, false);
                c.SetOptionalBoolean("firstRow", FirstRow, false);
                c.SetOptionalBoolean("xl97", Xl97, false);
                c.SetOptionalBoolean("xl2000", Xl2000, false);
                c.SetOptionalBoolean("textDates", DatesAsText, false);
                c.SetOptionalString("url",Url) ;
                c.SetOptionalString("post",Post) ;
                c.SetOptionalBoolean("htmlTables", HtmlTables, false);
                c.SetOptionalEnum<HtmlFormat>("htmlFormat", HtmlFormat, HtmlFormat.None);
                c.SetOptionalString("editPage", EditPage);
                c.WriteOptionalElement(Tables);
            }
        }


        private string editPage;

        public string EditPage
        {
            get { return editPage; }
            set { editPage = value; }
        }
	
        private HtmlFormat htmlFormat;

        public HtmlFormat HtmlFormat
        {
            get { return htmlFormat; }
            set { htmlFormat = value; }
        }
	
        private bool htmlTables;

        public bool HtmlTables
        {
            get { return htmlTables; }
            set { htmlTables = value; }
        }
	
        private string post;

        public string Post
        {
            get { return post; }
            set { post = value; }
        }
	
        private string url;

        public string Url
        {
            get { return url; }
            set { url = value; }
        }
	
        private bool xl2000;

        public bool Xl2000
        {
            get { return xl2000; }
            set { xl2000 = value; }
        }
	
        private bool textDates;

        public bool DatesAsText
        {
            get { return textDates; }
            set { textDates = value; }
        }
	
        private bool _xl97;

        public bool Xl97
        {
            get { return _xl97; }
            set { _xl97 = value; }
        }
	
        private bool _firstRow;

        public bool FirstRow
        {
            get { return _firstRow; }
            set { _firstRow = value; }
        }
	
        private bool consecutive;

        public bool Consecutive
        {
            get { return consecutive; }
            set { consecutive = value; }
        }
	
        private bool parsePre;

        public bool ParsePre
        {
            get { return parsePre; }
            set { parsePre = value; }
        }
	
        private bool sourceData;

        public bool SourceData
        {
            get { return sourceData; }
            set { sourceData = value; }
        }
	
        private bool xml;

        public bool Xml
        {
            get { return xml; }
            set { xml = value; }
        }
	
        private Tables tables;

        public Tables Tables
        {
            get { return tables; }
            set { tables = value; }
        }


        internal override void SetTypeIfNecessary()
        {
            Type = DataConnectionType.WebQuery;
        }

        internal override void Initialize()
        {
            Type = DataConnectionType.WebQuery;
        }
    }
}
